package com.flyee.viewer
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BevelFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.system.System;
	
	import mx.containers.HBox;
	import mx.containers.TitleWindow;
	import mx.controls.Button;
	import mx.core.Application;
	import mx.core.UIComponent;
	import mx.core.mx_internal;
	import mx.effects.Move;
	import mx.effects.Parallel;
	import mx.effects.Resize;
	import mx.effects.easing.Exponential;
	import mx.events.DragEvent;
	import mx.managers.CursorManager;
	use namespace mx_internal;
	//--------------------------------------
	//  Events
	//--------------------------------------
	// Drag events.
	[Event(name="dragStart" , type = "mx.events.DragEvent")]
	[Event(name="dragComplete" , type = "mx.events.DragEvent")]
	// Resize events.
	public class BaseWindowViewer extends TitleWindow implements Destroy
	{
		/*
		 * 窗口的最小长,宽
		 */
		public static const MINIMIZED_HEIGHT:Number = 40;
		public static const MINIMIZED_WIDTH:Number = 200;
		/*
		 * 窗口的当前大小状态
		 */
		public static const WINDOW_STATE_DEFAULT:Number = -1;
		public static const WINDOW_STATE_MINIMIZED:Number = 0;
		public static const WINDOW_STATE_MAXIMIZED:Number = 1;
		/*
		 * 拖动边框改变窗口大小的方向
		 */
		private const DRAG_LEFT:String = "drag_left";
		private const DRAG_RIGHT:String = "drag_right";
		private const DRAG_BOTTOM:String = "drag_bottom";
		private const DRAG_BOTTOM_LEFT:String = "drag_bottom_left";
		private const DRAG_BOTTOM_RIGHT:String = "drag_bottom_right";

		public var windowState:Number;
		// Corresponds to one of the WINDOW_STATE variables.
		public var index:Number;
		// Index within the layout.
		private var controlsHolder:HBox;
		private var minimizeButton:Button;
		private var maximizeRestoreButton:Button;
		private var headerDivider:Sprite;
		// Variables used for dragging the pod.
		private var dragStartMouseX:Number;
		private var dragStartMouseY:Number;
		private var dragStartX:Number;
		private var dragStartY:Number;
		private var dragMaxX:Number;
		private var dragMaxY:Number;
		/**
		 * 按钮控制
		 */
		private var _showControls:Boolean;
		private var _showControlsChanged:Boolean;
		private var _minimize:Boolean;
		private var _minimizeChanged:Boolean;
		private var _maximize:Boolean;
		private var _maximizeChanged:Boolean;

		//private var parallel:Parallel;							
		private var maximizeParallel:Parallel;// The main effect container.

		private var oldPosition:Point = null;
		private var oldSize:Point = null;

		private var dragDirection:String;
		private var newPosition:Point;
		private var newSize:Point;
		private var isCursorDown:Boolean = false;
		private var minSize:Point = null;

		public function BaseWindowViewer()
		{
			super();
			doubleClickEnabled = true;
			//setStyle("titleStyleName" , "podTitle");
			windowState = WINDOW_STATE_DEFAULT;
			horizontalScrollPolicy = "off";
			this.setStyle("fontSize",12);
			//this.addEventListener(PanelStateChangeEvent.RESTORE,resizePanelEvent);
			//defaultEffect();
			minSize = new Point(40,200);
			oldSize = new Point();
			oldPosition = new Point(this.x,this.y);
			//canSizePanel = true;
			//showControls = false;
		}
		/**
		 * 光标移动监听事件,根据光标所在窗口位置改变其样式 
		 * @param event
		 * 
		 */		
		private function cursorMove(event:MouseEvent):void
		{
			var x:Number = event.localX;
			var y:Number = event.localY;
			var rcClass:Class;
			
			//记录当前鼠标所点击的边框方向
			if( (x>0&&x<5)&&(y>25)&&(y<this.height-5) )
			{
				//rcClass = H_ResizeCursor;
			} 
			else if( (x>this.width-5)&&(x<this.width)&&(y>25)&&(y<this.height-5) )
			{
				//rcClass = H_ResizeCursor;
			}
			else if( (x>5)&&(x<this.width-5)&&(y>this.height-5)&&(y<this.height) )
			{
				//rcClass = V_ResizeCursor;
			}
			else if( (x>=0)&&(x<=5)&&(y>=this.height-5)&&(y<=this.height) )
			{
				//rcClass = LHV_ResizeCursor;
			}
			else if( (x>=this.width-5)&&(x<=this.width)&&(y>=this.height-5)&&(y<=this.height) )
			{
				//rcClass = RHV_ResizeCursor;
			}
			//判断鼠标是否是在边框上
			var con:BaseWindowViewer = event.target as BaseWindowViewer;
			if(!this.isCursorDown && rcClass && con)
			{
				CursorManager.getInstance().removeAllCursors();
				CursorManager.getInstance().setCursor(rcClass);
			}
			else
			{
				CursorManager.getInstance().removeAllCursors();
			}
		}
		/**
		 * 光标移出本面板的事件监听 
		 * @param event
		 * 
		 */		
		private function cursorOut(event:MouseEvent):void
		{
			if(CursorManager.getInstance().currentCursorID != CursorManager.NO_CURSOR
			&& !this.isCursorDown)
			{
				CursorManager.getInstance().removeAllCursors();
			}
		}
		/**
		 * 监听鼠标按下事件
		 * @param event
		 *
		 */		
		private function mouseDown(event:MouseEvent):void
		{
			var x:Number = event.localX;
			var y:Number = event.localY;

			//移除已有的临时重绘边框容器
			var ui:UIComponent 
				= UIComponent(Application.application.getChildByName(this.name));
			if(ui) 
			{
				Application.application.removeChild(ui);
				ui = null;
			}

			//记录当前鼠标所点击的边框方向
			if( (x>0&&x<5)&&(y>25)&&(y<this.height-5) )
			{
				this.dragDirection = DRAG_LEFT;
			} 
			else if( (x>this.width-5)&&(x<this.width)&&(y>25)&&(y<this.height-5) )
			{
				this.dragDirection = DRAG_RIGHT;
			}
			else if( (x>5)&&(x<this.width-5)&&(y>this.height-5)&&(y<this.height) )
			{
				this.dragDirection = DRAG_BOTTOM;
			}
			else if( (x>0)&&(x<5)&&(y>this.height-5)&&(y<this.height) )
			{
				this.dragDirection = DRAG_BOTTOM_LEFT;
			}
			else if( (x>this.width-5)&&(x<this.width)&&(y>this.height-5)&&(y<this.height) )
			{
				this.dragDirection = DRAG_BOTTOM_RIGHT;
			}
			//判断鼠标是否是在边框上
			var con:BaseWindowViewer = event.target as BaseWindowViewer;
			//最大化和最小化时禁止拖动窗口大小,绘出当前窗口边框矩形
			if(this.dragDirection && con
				&& this.windowState == WINDOW_STATE_DEFAULT)
			{
				this.isCursorDown = true;
				ui = new UIComponent();
				ui.name = this.name;
				ui.width = Application.application.width;
				ui.height = Application.application.height;
				Application.application.addChild(ui);
				var pen:Graphics = ui.graphics;
				var startP:Point = new Point(0,0);
				var globalStartP:Point = this.localToGlobal(startP);
				pen.lineStyle(1);
				pen.moveTo(globalStartP.x,globalStartP.y);
				pen.drawRect(globalStartP.x,globalStartP.y,this.width,this.height);
				Application.application.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
				Application.application.addEventListener(MouseEvent.MOUSE_MOVE,mouseMove);
			}
		}
		/**
		 * 监听鼠标弹起事件
		 * @param event
		 *
		 */		
		private function mouseUp(event:MouseEvent):void
		{
			this.dragDirection = null;
			this.isCursorDown = false;
			var ui:UIComponent 
				= UIComponent(Application.application.getChildByName(this.name));
			Application.application.removeEventListener(MouseEvent.MOUSE_UP,mouseUp);
			Application.application.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMove);
			
			if(CursorManager.getInstance().currentCursorID != CursorManager.NO_CURSOR)
			{
				CursorManager.getInstance().removeAllCursors();
			}

			if(ui)
			{
				//清除上次画笔绘出的边框图形
				var pen:Graphics = ui.graphics;
				pen.clear();
				//移除临时重绘边框容器
				Application.application.removeChild(ui);
				ui = null;
				//从内存中清除该容器
				System.gc();
			}

			//若边框有拖动改变大小，则重绘本窗口并且记录当前窗口大小
			if(newPosition && newSize)
			{
				var pod:BaseWindowViewer = this;
				var toy:int = 0;
				var para:Parallel = new Parallel();
				para.duration = 100;
				addResizeAndMoveToParallel(pod, para, newSize.x, newSize.y, newPosition.x,newPosition.y);
				para.play();

				this.oldPosition = new Point(newPosition.x,newPosition.y);
				this.oldSize = new Point(newSize.x,newSize.y);
			}

			if(newPosition)
				newPosition = null;
			if(newSize)
				newSize = null;
		}
		/**
		 * 监听鼠标按下后的拖动事件,改变本窗口的大小
		 * @param event
		 *
		 */		
		private function mouseMove(event:MouseEvent):void
		{
			var ui:UIComponent 
				= UIComponent(Application.application.getChildByName(this.name));
			if(!ui) return;

			var pen:Graphics = ui.graphics;
			pen.clear();
			pen.lineStyle(1);
			var startP:Point;
			var globalStartP:Point;
			var w:Number;
			var h:Number;
			var x:Number = mouseX;
			var y:Number = mouseY;

			//根据边框拖动的方向来重绘边框矩形
			if(this.dragDirection == DRAG_LEFT)
			{
				w = this.width - x;
				h = this.height;
			}
			else if(this.dragDirection == DRAG_RIGHT)
			{
				startP = new Point(0,0);
				w = x;
				h = this.height;
			}
			else if(this.dragDirection == DRAG_BOTTOM)
			{
				startP = new Point(0,0);
				w = this.width;
				h = y;
			}
			else if(this.dragDirection == DRAG_BOTTOM_LEFT)
			{
				w = this.width - x;
				h = y;
			}
			else if(this.dragDirection == DRAG_BOTTOM_RIGHT)
			{
				startP = new Point(0,0);
				w = x;
				h = y;
			}
			//若点击边框并且同时将其拖动，则重绘边框
			if(this.dragDirection)
			{
				/*
				 * 从边框左边拖动时限制左上角定点X坐标
				 * 使绘出的矩形边框4定点至少有一个点与原窗口边框重合
				 */
				if(this.dragDirection == DRAG_LEFT 
					|| this.dragDirection == DRAG_BOTTOM_LEFT)
				{
					if(x > this.width - minSize.x) 
						x = this.width - minSize.y;
					startP = new Point(x,0);
				}
				//限制边框的最小长宽值
				if(w < minSize.x) w = minSize.x;
				if(h < minSize.y) h = minSize.y;
				globalStartP = this.localToGlobal(startP);
				pen.moveTo(globalStartP.x,globalStartP.y);
				pen.drawRect(globalStartP.x,globalStartP.y,w,h);
				newPosition = new Point(globalStartP.x,globalStartP.y);
				newSize = new Point(w,h);
			}
		}
		
		public function dispose():void
		{
			maximizeRestoreButton.clearStyle("maximizeRestoreButton");
			minimizeButton.clearStyle("minimizeButton");
			
			controlsHolder = null;
			minimizeButton = null;
			maximizeRestoreButton = null;
			headerDivider = null;
			maximizeParallel = null;
			oldPosition = null;
			oldSize = null;
			newSize = null;
			minSize = null;
			dragStartMouseX = 0;
			dragStartMouseY = 0;
			dragStartX = 0;
			dragStartY= 0;
			dragMaxX = 0;
			dragMaxY = 0;
			_showControls = false;
			_showControlsChanged = false;
			_minimize = false;
			_minimizeChanged = false;
			_maximize = false;
			_maximizeChanged = false;
		}
		
		/**
		 * 创建子显示对象
		 *
		 */
		override protected function createChildren():void
		{
			super.createChildren();

			if (!headerDivider)
			{
				headerDivider = new Sprite();
				//FontFilter.graphMask(headerDivider.graphics , this.width , 10 , true);
				titleBar.addChild(headerDivider);
			}

			if (!controlsHolder)
			{
				controlsHolder = new HBox();
				controlsHolder.setStyle("paddingRight" , getStyle("paddingRight"));
				controlsHolder.setStyle("horizontalAlign" , "right");
				controlsHolder.setStyle("verticalAlign" , "middle");
				controlsHolder.setStyle("horizontalGap" , 1);
				controlsHolder.width = unscaledWidth - 20;
				controlsHolder.height = titleBar.height;
				rawChildren.addChild(controlsHolder);
			}

			if (!minimizeButton)
			{
				minimizeButton = new Button();
				minimizeButton.width = 16;
				minimizeButton.height = 16;
				minimizeButton.styleName = "minimizeButton";
				controlsHolder.addChild(minimizeButton);
			}

			if (!maximizeRestoreButton)
			{
				maximizeRestoreButton = new Button();
				maximizeRestoreButton.width = 16;
				maximizeRestoreButton.height = 16;
				maximizeRestoreButton.styleName = "maximizeRestoreButton";
				controlsHolder.addChild(maximizeRestoreButton);
			}
			oldPosition = new Point(this.x,this.y);
			oldSize = new Point(this.width,this.height);
			showControls = false;
		}

		/**
		 * 重写效果
		 * @param unscaledWidth
		 * @param unscaledHeight
		 *
		 */
		override protected function updateDisplayList(unscaledWidth:Number , unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth , unscaledHeight);
			//defaultEffect();
			// Shift the divider one pixel up if minimized so there isn't a gap between the left and right borders.
			// The bottom border is removed if minimized.
			var deltaY:Number = windowState == WINDOW_STATE_MINIMIZED ? -1 : 0;
			if(controlsHolder)
			{
				controlsHolder.y = titleBar.y;
				if (showCloseButton)
				{
					controlsHolder.width = unscaledWidth - 23;
				}
				else
				{
					controlsHolder.width = unscaledWidth - 7;
				}
				controlsHolder.height = titleBar.height;
			}
			if(headerDivider){
				//FontFilter.graphMask(headerDivider.graphics , this.width , 10 , true);
			}
			titleTextField.width = titleBar.width - getStyle("paddingLeft") - getStyle("paddingRight");
		}

		override protected function measure():void
		{
			super.measure();

			if (controlsHolder)
			{
				controlsHolder.y = titleBar.y;
			}
		}

		override protected function commitProperties():void
		{
			super.commitProperties();

			if (_showControlsChanged)
			{
				controlsHolder.visible = _showControls;
				_showControlsChanged = false;
			}
			if(!minimizeButton || !maximizeRestoreButton) return;

			if(windowState == WINDOW_STATE_MINIMIZED)
			{
				minimizeButton.visible = false;
			}
			else if(windowState == WINDOW_STATE_DEFAULT)
			{
				minimizeButton.visible = true;
			}
			else if(windowState == WINDOW_STATE_MAXIMIZED)
			{
				minimizeButton.visible = true;
			}

//			if (_minimizeChanged)
//			{
//				minimizeButton.visible = _minimize;
//				_minimizeChanged = false;
//			}
//
//			if (_maximizeChanged)
//			{
//				maximizeRestoreButton.selected = _maximize;
//				_maximizeChanged = false;
//			}
		}
		
		public function minimizeSize(wid:int,hei:int):void{
			minSize.x = wid;
			minSize.y = hei;
		}

		public function minimize():void
		{
			// Hide the bottom border if minimized otherwise the headerDivider and bottom border will be staggered. 
			//setStyle("borderSides", "left top right");
			windowState = WINDOW_STATE_MINIMIZED;
			maximizeRestoreButton.selected = true;
			_minimize = true;
			_minimizeChanged = true;
//			width = MINIMIZED_WIDTH;
//			height = MINIMIZED_HEIGHT;
//			showControls = false;
		}
		/**
		 *
		 *
		 */
		public function maximize():void
		{
			windowState = WINDOW_STATE_MAXIMIZED;
			_maximize = true;
			_maximizeChanged = true;
		}
		[Inspectable(category="General")]
		public function set showMinimizeButton(value:Boolean):void
		{
			_minimize = value;
			_minimizeChanged = true;
			invalidateProperties();
		}
		/**
		 * 该面板是否可以拖动的开关
		 * @param value
		 * 
		 */		
		public function set canDragMove(value:Boolean):void{
			if(value){
				addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
				titleBar.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownTitleBar);
			}else{
				this.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
				titleBar.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDownTitleBar);
			}
		}
		/**
		 * 该面板是否可以拉伸窗口大小开关
		 * @param value
		 * 
		 */		
		public function set canSizePanel(value:Boolean):void{
			if(value){
				this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown,false,0,true);
				this.addEventListener(MouseEvent.MOUSE_MOVE,cursorMove,false,0,true);
				this.addEventListener(MouseEvent.MOUSE_OUT,cursorOut,false,0,true);
			}else{
				this.removeEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
				this.removeEventListener(MouseEvent.MOUSE_MOVE,cursorMove);
				this.removeEventListener(MouseEvent.MOUSE_OUT,cursorOut);
			}
		}
		[Inspectable(category="General")]
		/**
		 * 显示最大，最小控制开关
		 * @param value
		 *
		 */		
		public function set showControls(value:Boolean):void
		{
			_showControls = value;
			_showControlsChanged = true;
			if(value){
				addListeners();
			}else{
				removeListeners();
			}
			invalidateProperties();
		}
		/**
		 * 得到标题框控件
		 * @return
		 *
		 */		
		public function get titleControlBar():UIComponent
		{
			return titleBar;
		}

		private function get availableWidth():Number
		{
			return Application.application.width-5;
		}

		private function get availableHeight():Number
		{
			return 0;
		}

		private function get availableMaximizedHeight():Number
		{
			return Application.application.height-5;
		}

		private function get minimizedPodY():Number
		{
			return 0;
		}

		/**
		 * 添加监听
		 *
		 */
		private function addListeners():void
		{
			titleBar.addEventListener(MouseEvent.DOUBLE_CLICK , clickMaximizeRestoreEvent);
//			titleBar.addEventListener(MouseEvent.CLICK , clickTitleBarEvent);
			minimizeButton.addEventListener(MouseEvent.CLICK , clickMinimizeEvent);
			maximizeRestoreButton.addEventListener(MouseEvent.CLICK , clickMaximizeRestoreEvent);
			addEventListener(DragEvent.DRAG_COMPLETE,dragCompleteEvent);
		}

		private function removeListeners():void{
			titleBar.removeEventListener(MouseEvent.DOUBLE_CLICK , clickMaximizeRestoreEvent);
//			titleBar.removeEventListener(MouseEvent.CLICK , clickTitleBarEvent);
			minimizeButton.removeEventListener(MouseEvent.CLICK , clickMinimizeEvent);
			maximizeRestoreButton.removeEventListener(MouseEvent.CLICK , clickMaximizeRestoreEvent);
			removeEventListener(DragEvent.DRAG_COMPLETE,dragCompleteEvent);
		}

		private function defaultEffect():void
		{
			layout = "absolute";
			//setStyle("backgroundColor" , ApplicationContext.getInstance().panelbgColor);
			//var glowFilter:GlowFilter = FontFilter.glowFilter(0x000000);
			//var bevelFilter:BevelFilter = FontFilter.bevelFilter();
		//this.filters = [bevelFilter , glowFilter];
		}

		private function dragCompleteEvent(event:DragEvent):void{
			if(this.x != 0){
				oldPosition.x =  this.x;
				oldPosition.y = this.y;
			}
		}

		private function addResizeAndMoveToParallel(target:BaseWindowViewer, parallel:Parallel, widthTo:Number, heightTo:Number, xTo:Number, yTo:Number):void
		{
			var resize:Resize = new Resize(target);
			//限制拖动改变窗口大小的最小范围
			if(widthTo < MINIMIZED_WIDTH) widthTo = MINIMIZED_WIDTH;
			resize.widthTo = widthTo;
			if(heightTo < MINIMIZED_HEIGHT) heightTo = MINIMIZED_HEIGHT;
			resize.heightTo = heightTo;
			resize.easingFunction = Exponential.easeOut;
			parallel.addChild(resize);

			var move:Move = new Move(target);
			move.xTo = xTo;
			move.yTo = yTo;
			move.easingFunction = Exponential.easeOut;
			parallel.addChild(move);
		}

		private function onMouseDown(event:Event):void
		{
			// Moves the pod to the top of the z-index.
			parent.setChildIndex(this , parent.numChildren - 1);
		}

		private function clickMinimizeEvent(event:MouseEvent):void
		{
			//dispatchEvent(new PanelStateChangeEvent(PanelStateChangeEvent.MINIMIZE));
			// Set the state after the event is dispatched so the old state is still available.
			minimize();

			var pod:BaseWindowViewer = this;
			var para:Parallel = new Parallel();
			para.duration = 1000;
			addResizeAndMoveToParallel(pod, para, MINIMIZED_WIDTH, MINIMIZED_HEIGHT, oldPosition.x,oldPosition.y);
			para.play();
		}

		private function clickMaximizeRestoreEvent(event:MouseEvent = null):void
		{
//			showControls = true;
			var pod:BaseWindowViewer = this;
			if (windowState == WINDOW_STATE_DEFAULT)
			{
				//dispatchEvent(new PanelStateChangeEvent(PanelStateChangeEvent.MAXIMIZE));
				// Call after the event is dispatched so the old state is still available.

				var toy:int = 0;
				maximizeParallel = new Parallel();
				maximizeParallel.duration = 1000;
				addResizeAndMoveToParallel(pod, maximizeParallel, availableWidth, availableMaximizedHeight, 0,toy);
				maximizeParallel.play();

				windowState = WINDOW_STATE_MAXIMIZED;
				maximizeRestoreButton.selected = true;
			}
			else if (windowState == WINDOW_STATE_MAXIMIZED
				|| windowState == WINDOW_STATE_MINIMIZED) 
			{
				if (maximizeParallel != null && maximizeParallel.isPlaying)
					maximizeParallel.pause();

				maximizeParallel = new Parallel();
				addResizeAndMoveToParallel(pod, maximizeParallel, oldSize.x, oldSize.y, oldPosition.x, oldPosition.y);
				maximizeParallel.play();

				windowState = WINDOW_STATE_DEFAULT;
				maximizeRestoreButton.selected = false;
			}
		}

		private function clickTitleBarEvent(event:MouseEvent):void
		{

			if (windowState == WINDOW_STATE_MINIMIZED)
			{
				// Add the bottom border back in case we were minimized.
				setStyle("borderSides" , "left top right bottom");
				clickMaximizeRestoreEvent();
			}
		}

		/**
		 * 窗口拖动事件
		 * @param event
		 *
		 */
		private function onMouseDownTitleBar(event:MouseEvent):void
		{

			if (windowState != WINDOW_STATE_MAXIMIZED)
				// Only allow dragging if we are not in the max state.
			{
				dispatchEvent(new DragEvent(DragEvent.DRAG_START));
				dragStartX = x;
				dragStartY = y;
				dragStartMouseX = parent.mouseX;
				dragStartMouseY = parent.mouseY;
				dragMaxX = parent.width - width;
				dragMaxY = parent.height - height;
				// Use the stage so we get mouse events outside of the browser window.
				stage.addEventListener(MouseEvent.MOUSE_MOVE , onMouseMove);
				stage.addEventListener(MouseEvent.MOUSE_UP , onMouseUp);
			}
		}

		/**
		 * 窗口移动
		 * @param e
		 *
		 */
		private function onMouseMove(e:MouseEvent):void
		{
			// Make sure we don't go off the screen on the right.
			var targetX:Number = Math.min(dragMaxX , dragStartX + (parent.mouseX - dragStartMouseX));
			// Make sure we don't go off the screen on the left.
			x = Math.max(0 , targetX);
			// Make sure we don't go off the screen on the bottom.
			var targetY:Number = Math.min(dragMaxY , dragStartY + (parent.mouseY - dragStartMouseY));
			// Make sure we don't go off the screen on the top.
			y = Math.max(0 , targetY);
		}

		/**
		 * 拖动停止
		 * @param event
		 *
		 */
		private function onMouseUp(event:MouseEvent):void
		{
			dispatchEvent(new DragEvent(DragEvent.DRAG_COMPLETE));
			Application.application.stage.removeEventListener(MouseEvent.MOUSE_MOVE , onMouseMove);
			Application.application.stage.removeEventListener(MouseEvent.MOUSE_UP , onMouseUp);
		}

		/**
		 * 自适应大小
		 * @param event
		 *
		 */
		protected function resizePanelEvent(event:Event):void
		{
			//MyLog.info("panel resize!!!!!");
		/* validateNow();
		 validateSize(true);*/
		}
	}
}
